package com.example.backstage.config.security;

import com.example.backstage.entity.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority;

import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Data
public class LoginUserDetails implements UserDetails {

    private User user;

    public LoginUserDetails(User user) {
        this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        SimpleGrantedAuthority user1 = new SimpleGrantedAuthority("ROLE_"+"user");
        return List.of(user1);
    }

    @Override
    public String getPassword() {
        if (Objects.isNull(this.user)) return null;
        return this.user.getPassword();
    }

    @Override
    public String getUsername() {
        if (Objects.isNull(this.user)) return null;
        return this.user.getName();
    }

}
